//
//  OrderVC.m
//  DiningCar-Business
//
//  Created by 吕晶 on 2020/4/7.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "OrderVC.h"
#import "OrderNavBar.h"
#import "OrderMainModel.h"
#import "OrderHomeCell.h"

@interface OrderVC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) OrderNavBar *navBar;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArray;

@end

@implementation OrderVC

-(NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
        OrderMainModel *model = [OrderMainModel new];
        model.buyer_name = @"张珊珊";
        model.buyer_mobile = @"17649876789";
        model.gender = @"2";
        model.order_status = @"1";
        model.order_code = 600866;
        model.pay_price = @"25";
        model.fee = 5;
        model.income = 20;
        model.order_no = @"6165476488965";
        model.order_status = @"1";
        OrderGoodModel *goodM = [OrderGoodModel new];
        goodM.title = @"核桃";
        goodM.amount = 1;
        goodM.price = 25;
        model.list = @[goodM,goodM,goodM,goodM,goodM,goodM,goodM];
        
        OrderMainModel *model1 = [OrderMainModel new];
        model1.buyer_name = @"张珊珊";
        model1.buyer_mobile = @"17649876789";
        model1.gender = @"2";
        model1.order_status = @"1";
        model1.order_code = 600866;
        model1.pay_price = @"25";
        model1.fee = 5;
        model1.income = 20;
        model1.order_no = @"6165476488965";
        model1.order_status = @"2";
        model1.list = @[goodM,goodM,goodM];
        [_dataArray addObject:model];
        [_dataArray addObject:model1];
    }
    return _dataArray;
}

-(OrderNavBar *)navBar {
    if (!_navBar) {
        _navBar = [[OrderNavBar alloc] initWithFrame:CGRectMake(0, 0, ScreenW, NaviHeight)];
        _navBar.titleStr = @"新订单";
    }
    return _navBar;
}

-(UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navBar.nim_bottom, ScreenW, ScreenH - NaviHeight - TabbarHeight) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.backgroundColor = Color_backgroundColor;
    }
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    [self.view addSubview:self.navBar];
    [self.view addSubview:self.tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderHomeCell *cell = [OrderHomeCell OrderHomeCellWithTableView:tableView];
    cell.orderModel = self.dataArray[indexPath.row];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderHomeCell *cell = [OrderHomeCell OrderHomeCellWithTableView:tableView];
    cell.orderModel = self.dataArray[indexPath.row];
    return cell.height;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 10)];
    view.backgroundColor = Color_backgroundColor;
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

@end
